import java.util.HashMap;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 姚东名
 * Date: 2024-10-05
 * Time: 10:20
 */
class Person {
    public String id;
    public Person(String id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(id, person.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
public class Test {
    public static void main(String[] args) {
        HashMap<String, Integer> hashMap = new HashMap<>();
        hashMap.put("haha", 10);
    }
    public static void main2(String[] args) {
        //在没有重写hashCode和equals方法时
        Person person1 = new Person("5509");
        Person person2 = new Person("5509");//认为身份证号相同就是同一个人
        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());//二者的整数不一样，重写之后就相同了

        HashBuck2<Person, String> hashBuck2 = new HashBuck2<>();
        hashBuck2.put(person1, "张三");
        System.out.println(hashBuck2.getVal(person2));//当打印`张三`时，证明person1和person2是同一个对象
    }
    public static void main1(String[] args) {
        HashBuck hashBuck = new HashBuck();
        hashBuck.push(1,111);
        hashBuck.push(11,111111);
        hashBuck.push(14,141414);
        hashBuck.push(4,444);
        hashBuck.push(2,222);
        hashBuck.push(15,151515);
        hashBuck.push(6,666);
        hashBuck.push(5,555);

        System.out.println(hashBuck.getVal(15));
    }
}
